/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2019/12/8 5:34 下午
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.example.spring.event.listener;

import com.example.spring.event.common.EventSourceTypeEnum;
import com.example.spring.event.sender.MailSender;
import com.example.spring.event.source.BusinessEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

/**
 * <p>
 * SmartApplicationListener
 * 消息监听【支持类型简单过滤】
 * </p>
 *
 * @author Yi
 * @version V1.0.0
 * @date 2019/12/8 5:34 下午
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人}  2019/12/8
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Component
public class BusinessEventListener implements SmartApplicationListener {

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return BusinessEvent.class.equals(eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        BusinessEvent ev = ((BusinessEvent) event);
        if (EventSourceTypeEnum.EVENT_SOURCE_TYPE_ENUM_BUSINESS_1.equals(ev.getSourceType())) {
            System.out.println("BusinessEventListener 收到消息 "+ev.getEventSource()+ ev.getMessage());
        }else{
            System.out.println("BusinessEventListener 忽略消息"+ev.getEventSource()+ ev.getMessage());
        }
    }

    @Override
    public boolean supportsSourceType(Class<?> sourceType) {
        System.out.println("BusinessEventListener 事件源"+sourceType.getName());
        return true;
    }
}
